<template>
	<view class="loading">
		<view class="loading-text">{{status_message}}</view>
	</view>
</template>

<script>

	export default {
		data() {
			return {
				status_message : ''
			};
		},
		
		async onLoad() {
			
			//加载怪物数据
			let monsters = await this.$request({name : 'monster',method : 'get_monsters'})
			getApp().globalData['GAME_DATA']['monsters'] = monsters.data;
			this.status_message = '加载怪物数据...'
			
			//加载boss数据
			let boss = await this.$request({name : 'boss',method : 'get_boss'})
			getApp().globalData['GAME_DATA']['boss'] = boss.data;
			this.status_message = '加载boss数据...'
			
			//加载物品数据
			let items = await this.$request({name : 'item',method : 'get_items'})
			getApp().globalData['GAME_DATA']['items'] = items.data;
			this.status_message = '加载物品数据...'
			
			//加载地图数据
			let map = await this.$request({name : 'map',method : 'get_map'})
			getApp().globalData['GAME_DATA']['map'] = map.data;
			this.status_message = '加载地图数据...'
			
			//加载游戏配置数据
			let config = await this.$request({name : 'config',method : 'get_config'})
			getApp().globalData['GAME_DATA']['config'] = config.data;
			this.status_message = '加载游戏配置数据...';
			
			// 使用
			deepFreeze(getApp().globalData['GAME_DATA']);
			
			protectGetApp();
			

			uni.reLaunch({
				url : '/pages/game/game'
			})
		},

	}
	
	function protectGetApp() {
	    const originalGetApp = getApp;
	
	    getApp = function() {
	        const appInstance = originalGetApp.apply(this, arguments);
	
	        return new Proxy(appInstance, {
	            set(target, prop, value) {
	               
	                return true;  // 表示该属性的设置操作已成功，但实际上我们并没有更改它
	            },
	            defineProperty(target, prop, descriptor) {
	                
	                return false;
	            },
	            deleteProperty(target, prop) {
	               
	                return false;
	            }
	        });
	    };
	}
	
	
	function deepFreeze(obj) {

	  const propNames = Object.getOwnPropertyNames(obj);

	  for (let name of propNames) {
	    let value = obj[name];
	    if (value && typeof value === "object") {
	      deepFreeze(value);
	    }
	  }

	  return Object.freeze(obj);
	}
	
	
	
	

</script>

<style lang="scss">
	.loading-text{
		margin:10px;
	}
</style>
